package cn.edu.csmzxy.rk233x.auth_system.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
 * @author wumxing
 * @date 2025/10/15 9:54
 * @description  HTTP响应DTO
 */
@Data
@Schema(description = "统一响应结果")
public class ResultDTO<T> {

    @Schema(description = "状态码（200=成功）")
    private Integer code;

    @Schema(description = "响应消息")
    private String message;

    @Schema(description = "响应数据")
    private T data;

    private ResultDTO() {}

    public static <T> ResultDTO<T> success() {
        return success("操作成功");
    }

    public static <T> ResultDTO<T> success(String message) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(200);
        result.setMessage(message);
        return result;
    }

    public static <T> ResultDTO<T> success(T data) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(200);
        result.setMessage("操作成功");
        result.setData(data);
        return result;
    }

    public static <T> ResultDTO<T> success(T data, String message) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(200);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> ResultDTO<T> fail(Integer code, String message) {
        ResultDTO<T> result = new ResultDTO<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> ResultDTO<T> fail(String message) {
        return fail(500, message);
    }
}